-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top recent trading pages #7710
Top recent trading pages #7710
Conversation
Build files for 643d395 are ready:
|
Size Change: +641 B (0%) Total Size: 1.41 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const getReportOptions = () => { | ||
const today = new Date(); | ||
const todayDateString = getDateString( today ); | ||
|
||
const yesterday = getPreviousDate( todayDateString, 1 ); | ||
const twoDaysAgo = getPreviousDate( todayDateString, 2 ); | ||
const threeDaysAgo = getPreviousDate( todayDateString, 3 ); | ||
|
||
const dates = { | ||
startDate: threeDaysAgo, | ||
endDate: yesterday, | ||
}; | ||
|
||
const reportOptions = { | ||
...dates, | ||
dimensions: [ 'pagePath' ], | ||
dimensionFilters: { | ||
'customEvent:googlesitekit_post_date': { | ||
filterType: 'inListFilter', | ||
value: [ | ||
yesterday.replace( /-/g, '' ), | ||
twoDaysAgo.replace( /-/g, '' ), | ||
threeDaysAgo.replace( /-/g, '' ), | ||
], | ||
}, | ||
}, | ||
metrics: [ { name: 'screenPageViews' } ], | ||
orderby: [ | ||
{ | ||
metric: { | ||
metricName: 'screenPageViews', | ||
}, | ||
desc: true, | ||
}, | ||
], | ||
limit: 3, | ||
}; | ||
|
||
return [ reportOptions, dates ]; | ||
}; | ||
function TopRecentTrendingPages( { Widget } ) { | ||
const viewOnlyDashboard = useViewOnly(); | ||
|
||
const dates = getReportOptions()[ 1 ]; | ||
|
||
const reportOptions = getReportOptions()[ 0 ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this function outside of the component? We tend to place functions that a component uses inside them.
Given this is only for this component, let's move it inside the component.
In fact, you call this function from inside the component multiple times but it's probably worth calling it once and storing the results… or even just declaring these variables all directly in the component. I don't see why we wouldn't do that 🤔
const getReportOptions = () => { | |
const today = new Date(); | |
const todayDateString = getDateString( today ); | |
const yesterday = getPreviousDate( todayDateString, 1 ); | |
const twoDaysAgo = getPreviousDate( todayDateString, 2 ); | |
const threeDaysAgo = getPreviousDate( todayDateString, 3 ); | |
const dates = { | |
startDate: threeDaysAgo, | |
endDate: yesterday, | |
}; | |
const reportOptions = { | |
...dates, | |
dimensions: [ 'pagePath' ], | |
dimensionFilters: { | |
'customEvent:googlesitekit_post_date': { | |
filterType: 'inListFilter', | |
value: [ | |
yesterday.replace( /-/g, '' ), | |
twoDaysAgo.replace( /-/g, '' ), | |
threeDaysAgo.replace( /-/g, '' ), | |
], | |
}, | |
}, | |
metrics: [ { name: 'screenPageViews' } ], | |
orderby: [ | |
{ | |
metric: { | |
metricName: 'screenPageViews', | |
}, | |
desc: true, | |
}, | |
], | |
limit: 3, | |
}; | |
return [ reportOptions, dates ]; | |
}; | |
function TopRecentTrendingPages( { Widget } ) { | |
const viewOnlyDashboard = useViewOnly(); | |
const dates = getReportOptions()[ 1 ]; | |
const reportOptions = getReportOptions()[ 0 ]; | |
function TopRecentTrendingPages( { Widget } ) { | |
const viewOnlyDashboard = useViewOnly(); | |
const today = new Date(); | |
const todayDateString = getDateString( today ); | |
const yesterday = getPreviousDate( todayDateString, 1 ); | |
const twoDaysAgo = getPreviousDate( todayDateString, 2 ); | |
const threeDaysAgo = getPreviousDate( todayDateString, 3 ); | |
const dates = { | |
startDate: threeDaysAgo, | |
endDate: yesterday, | |
}; | |
const reportOptions = { | |
...dates, | |
dimensions: [ 'pagePath' ], | |
dimensionFilters: { | |
'customEvent:googlesitekit_post_date': { | |
filterType: 'inListFilter', | |
value: [ | |
yesterday.replace( /-/g, '' ), | |
twoDaysAgo.replace( /-/g, '' ), | |
threeDaysAgo.replace( /-/g, '' ), | |
], | |
}, | |
}, | |
metrics: [ { name: 'screenPageViews' } ], | |
orderby: [ | |
{ | |
metric: { | |
metricName: 'screenPageViews', | |
}, | |
desc: true, | |
}, | |
], | |
limit: 3, | |
}; |
dimensions: | ||
KEY_METRICS_WIDGETS[ KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES ] | ||
.requiredCustomDimensions?.[ 0 ], | ||
reportOptions: getReportOptions()[ 0 ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, this is why we have the function outside the component. That would be worth noting in a comment at the top of the file, as it's unclear otherwise and unexpected 😄
Additionally, let's have the function return an object so the reportOptions
and dates
are keys rather than using numerical indexes for the returned values. getReportOptions().reportOptions
is more readable than getReportOptions()[ 0 ]
.
Even better might be getReportOptions()
only returning the report options, given the dates are simple and consistent/hardcoded we could either specify them in both the function and the component, or have a separate getDateRange()
function. 🤔
const today = new Date(); | ||
const todayDateString = getDateString( today ); | ||
|
||
const yesterday = getPreviousDate( todayDateString, 1 ); | ||
const twoDaysAgo = getPreviousDate( todayDateString, 2 ); | ||
const threeDaysAgo = getPreviousDate( todayDateString, 3 ); | ||
|
||
const reportOptions = { | ||
startDate: threeDaysAgo, | ||
endDate: yesterday, | ||
dimensions: [ 'pagePath' ], | ||
dimensionFilters: { | ||
'customEvent:googlesitekit_post_date': { | ||
filterType: 'inListFilter', | ||
value: [ | ||
yesterday.replace( /-/g, '' ), | ||
twoDaysAgo.replace( /-/g, '' ), | ||
threeDaysAgo.replace( /-/g, '' ), | ||
], | ||
}, | ||
}, | ||
metrics: [ { name: 'screenPageViews' } ], | ||
orderby: [ | ||
{ | ||
metric: { | ||
metricName: 'screenPageViews', | ||
}, | ||
desc: true, | ||
}, | ||
], | ||
limit: 3, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be exported from the component's file so the story can reuse them, rather than specifying them again here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tofumatt Great point, thanks. I extracted it into a new dir, so other custom dimensions dependant widgets can also use it.
@@ -0,0 +1,208 @@ | |||
/** | |||
* TopCitiesWidget component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This title doesn't match the filename/component name, by that raises a separate question: why rename this anyway? With this new filename it's the only KMW in that folder I can see whose component name/filename doesn't end with Widget
. I don't know what the motivation for that is, as I didn't see it in the ACs of the issue and it was mentioned in the IB but I'm not sure why.
cc @nfmohit who wrote the IB, maybe you can shed some light on the renaming here? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tofumatt. The naming in the IB was an oversight. Since all widget names end with Widget
, we should also do the same here. Thanks for checking!
@zutigrm This branch also has merge conflicts that need resolving. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the refactoring here introduced a bug, but I can fix it then get this merged 👍🏻
|
||
function TopRecentTrendingPagesWidget( { Widget } ) { | ||
const viewOnlyDashboard = useViewOnly(); | ||
|
||
const dates = getReportOptions()[ 1 ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is no longer returning an array (or the dates at all) so this will fail 🤔
if ( ! components.length ) { | ||
|
||
// Filter out the custom-dimensions-report-options directory | ||
const filteredComponents = components.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @zutigrm, are these changes to this file needed or could they have been introduced by accident? When I remove them and run the test suite locally, it still passes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @techanvil, they are not now, as the folder structure is removed in favour of date/report options functions being in the same file. I will remove that from the test in my next issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks @zutigrm!
Summary
Addresses issue:
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist